library Wave10a initializer init requires LegacySystem

    private function MarineCommandChapter2a takes nothing returns nothing
        call SetPlayerTechResearched(GetEnumPlayer(),'R004',1) //Gunship Support
        call SetPlayerTechResearched(GetEnumPlayer(),'R00Z',1) //IUL Fire Mission
    endfunction


    private function Wave10aCreeps takes nothing returns nothing
        call PlatoonReinforcements.execute()
        set udg_ACA[12] = true
        call ForForce(udg_EchoCompany,function MarineCommandChapter2a)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "0320 Local Time" )
        call C130Wave10.execute()
        if udg_Mode==4 and udg_Players>0 then
            call ALICEText(10.0, "Chapter 1 Complete. |cff1e90ff100 XP|r awarded to " + GetPlayerName(ConvertedPlayer(udg_Sorted[1])) )
            set udg_Experience[udg_Sorted[1]] = udg_Experience[udg_Sorted[1]] + 100
        endif
        call PolledWait(30.0*udg_Pace)
        call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'n004',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnEastBottom,Player(13),'n003',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(14),'z002',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnTownWestCave,Player(13),'n004',2+udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'n004',2+udg_Spawn)
        call RandomSpawn('u000',2,GetRandomInt(0,udg_Spawn)) //Futty
        call SpawnRectRandom(gg_rct_SpawnWestTop,Player(14),'n004',2+udg_Spawn)
        call RandomSpawn('z00C',2,GetRandomInt(0,1)) //Assasin
        call RandomSpawn('n002',1,GetRandomInt(0,udg_Spawn)) //Devourer
        if udg_Players==udg_InitialPlayers then
            call GankMarine(Player(13),'u005',2+udg_Spawn,1600,2000)
        endif
        call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'nsw1',udg_InitialPlayers)
        call GankMarine(Player(13),'n004',2+udg_Spawn,1600,2000)
        call GankMarine(Player(13),'n004',2+udg_Spawn,1600,2000)
        call PolledWait(30.0*udg_Pace)
        call RandomSpawn('u00L',4,IMinBJ(5, udg_Players)) //Blink
        call GankMarine(Player(14),'n004',2+udg_Spawn,1600,2000)
        call GankMarine(Player(14),'n004',2+udg_Spawn,1600,2000)
        if udg_Players>=6 then
            call RandomSpawn('ugar',1,2)
            call RandomSpawn('n002',1,2)
        endif
        call PolledWait(30.0*udg_Pace)
        call RandomSpawn('ugar',1,GetRandomInt(1,udg_Spawn)) //Gargoyle
        call GankMarine(Player(13),'n005',2+udg_Spawn,1600,2000)
    endfunction

    private function OsirisHaunt takes nothing returns nothing
        local integer i = GetRandomInt(1,udg_Players)
        local effect sfx
        local real x = GetUnitX(udg_Hero[udg_Sorted[i]])+GetRandomReal(-250.0,250.0)
        local real y = GetUnitY(udg_Hero[udg_Sorted[i]])+GetRandomReal(-250.0,250.0)
        local real x2
        local real y2
        if GetWidgetLife(udg_DeltaLeader)<50.0 then
            call DestroyTrigger(GetTriggeringTrigger())
            set udg_DMDeaths[1] = 0
        elseif GetRandomInt(1,udg_DMDeaths[1])!=1 then
            return
        endif
        set sfx = AddSpecialEffectTarget( "Abilities\\Spells\\Orc\\TrollBerserk\\HeadhunterWEAPONSLeft.mdl",udg_DeltaLeader,"chest" )
        call DestroyEffect(sfx)
        call SetUnitX(udg_DeltaLeader,x)
        call SetUnitY(udg_DeltaLeader,y)
        call PolledWait(2.)
        call DestroyEffect(sfx)
        set sfx = null
        if udg_InitialPlayers>2 then
            set x2 = GetUnitX(udg_DeltaLeader)+GetRandomReal(-1500.0,1500.0)
            set y2 = GetUnitY(udg_DeltaLeader)+GetRandomReal(-1500.0,1500.0)
        else
            set x2 = GetUnitX(udg_DeltaLeader)+GetRandomReal(-2500.0,2500.0)
            set y2 = GetUnitY(udg_DeltaLeader)+GetRandomReal(-2500.0,2500.0)
        endif
        if x2>14800.0 then
            set x2=14800.0
        endif
        if y2>16400.0 then
            set y2=16400.0
        endif
        if GetWidgetLife(udg_DeltaLeader)>0.405 then
            call SetUnitX(udg_DeltaLeader,x2)
            call SetUnitY(udg_DeltaLeader,y2)
        endif
        if GetRandomInt(0,5)==1 and udg_Players<1 then
            call GeneralText(5.0, "|cffcd950cMarine|r : Watch out!" )
        elseif GetRandomInt(0,5)==1 and udg_Players<1 then
            call GeneralText(5.0, "|cffcd950cMarine|r : Run!" )
        elseif GetRandomInt(0,5)==1 and udg_Players<1 then
            call GeneralText(5.0, "|cffcd950cMarine|r : Son of a bitch!" )
        endif
    endfunction


    private function OsirisSpawn takes nothing returns nothing
        local trigger t = CreateTrigger()
        local location l = GetRandomLocInRect(GetPlayableMapRect())
        local real blink = 8.0
        set udg_DMDeaths[1] = 3
        call PolledWait(GetRandomReal(1.0,240.0))
        if udg_Players<5 or udg_SquadXP<75000 then
            set udg_DeltaLeader = CreateUnit(Player(14),'U00E',GetLocationX(l),GetLocationY(l),0.0)
        else
            set udg_DeltaLeader = CreateUnit(Player(14),'U00F',GetLocationX(l),GetLocationY(l),0.0) //Type 2
        endif
        call SuspendHeroXP(udg_DeltaLeader,true)
        if udg_Mode==2 then
            set blink=18.0
        elseif udg_SquadXP>65000 then
            set blink=5.5
        endif
        if udg_SquadXP<60000 then
            call ALICEText(5.0, "|cffcd950cALICE|r : Osiris class entity detected. Entity capable of swift displacement. Extreme caution advised." )
        endif
        if udg_Players>3 then
            call TriggerRegisterTimerEvent(t,blink,true)
            call TriggerAddAction(t, function OsirisHaunt)
            if udg_Players>6 and udg_SquadXP>85000 then
                call UnitAddAbility(udg_DeltaLeader,'A008') //Feedback
            endif
        endif
        set t = null
        call RemoveLocation(l)
        set l = null
    endfunction

    private function Wave10a takes nothing returns nothing
        local integer probstart = 10
        local integer probend = 35
        local real trans = 0.0
         
        if udg_Players<1 or udg_Chapter==2 then
            return
        endif
        if GetRandomInt(0,10)==1 then
            set trans = 40.0
        endif

        call SetPlayerName( Player(9), "MAG-1" )
        set udg_Intermission = true
        set udg_XPFactor = udg_XPFactor * 1.2
        set udg_Chapter = 2
        set udg_Lighting = true
        call SquadRatingCalc.execute()
        call PauseAllUnitsBJ(true)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(false,1.0)
        call ClearTextMessages()
        call PolledWait(1.5)
        call StartSound(gg_snd_Message)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "                                                                                   |cff8b864eRevelation|r" )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call PauseAllUnitsBJ(true)
        call PolledWait(5.5)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(true,1.0)
        call ClearTextMessages()
        set udg_Lighting = false
        call PolledWait(1.)
        set udg_Intermission = false
        call PauseAllUnitsBJ(false)
        call IntermissionRestore()
        call PolledWait(5.)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call TriggerSleepAction(0.)
        call IntermissionRestore()
        call SetImmortalSpawnEnabled(true)
        call SetCrepitusSpawnEnabled(true)
        call SetGhoulSpawnEnabled(true)
        call SetRevelationSpawnEnabled(true)
        
        if udg_SquadXP>60000 then
            set probstart=40
            set probend=80
        elseif udg_SquadXP>35000 then
            set probstart=25
            set probend=55
        endif
        call GeneralText(3.0, "|cffcd950cMarine|r : Let's get to a more secure location." )
        call PolledWait(8.)
        call ALICEText(5.0, "|cffcd950cALICE|r : Third Platoon's calculated probability of survival is " + I2S(GetRandomInt(1,60)) + " percent." )
        call PolledWait(4.)
        call GeneralText(5.0, "|cffcd950cMarine|r : Those damned things.. don't have a working CPU. We're.. closer to 100 percent." )
        call PolledWait(3.)
        call ALICEText(5.0, "|cffcd950cALICE|r : This ALICE unit is functioning at optimal condition." )
        call PolledWait(5.0*udg_Pace)
        call GeneralText(5.0, "|cffcd950cMarine|r : Jesus! Where'd that thing learn to talk back. Iron Hand.. what now?" )
        call PolledWait(5.0*udg_Pace)
        call GeneralText(8.0, "|cffcd950cBattalion|r : Hold your ground. We've dispatched Fox Company to your sector." )
        set udg_CurrentWave = 10
        call GenericActions.execute()
        call OsirisSpawn.execute()
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Establish a secure perimeter" )
        call QuestSetDescription(udg_CurrentOrders, "A reactionary force is on its way. Echo Company must maintain the strongpoint. Take stock of supplies and distribute ammunition evenly.|n|nWe've deployed a second wave of C-130 supplies. Your squad is probably low on supplies. Run a sweep across the sector and pick up what you need." )
        call ALICE2Text(5.0, "|cff8b864eNew Objective|r : Establish a secure perimeter and wait for reactionary force." )
        call MissionUpdate.execute()
        call PolledWait(13.0*udg_Pace)
        call GeneralText(5.0, "|cffcd950cMarine|r : We're on our own with limited support. Zack's closing in on us and he's hungry. Being in this company is like winning the lottery every fucking day." )
        call Wave10aCreeps.execute()
        call PolledWait(40.0*udg_Pace)
        set udg_DMDeaths[1] = 1
        call PolledWait(90.0*udg_Pace)
        if udg_Players>0 then
            call ExecuteRegisteredFunction("Wave11a")
            //call Wave11a.execute()
        endif
    endfunction
    
    private function init takes nothing returns nothing
        call RegisterFunction("Wave10a", function Wave10a) 
    endfunction
    
endlibrary